package com.mall.untils;

import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by sa on 2015/4/15 16:16
 */
public class HttpGetUtil {

	static Logger logger = Logger.getLogger(HttpGetUtil.class);

	public static String getStringByGet(String url_get) {

		try {

			URL url = new URL(url_get);

			HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();

			httpConn.connect();

			InputStream inputStream = httpConn.getInputStream();

			// 对应的字符编码转换
			Reader reader = new InputStreamReader(inputStream, "UTF-8");
			BufferedReader bufferedReader = new BufferedReader(reader);

			StringBuffer sb = new StringBuffer();

			String str = null;

			while ((str = bufferedReader.readLine()) != null) {
				sb.append(str);
			}
			reader.close();
			httpConn.disconnect();
			return sb.toString();

		} catch (Exception ex) {
			logger.info(ex.getMessage());
			return null;
		}
	}
}
